class TraitEffectsController < ApplicationController
  before_filter :login_required
  
  def authorized?(user = current_player())
    return user.admin?
  end
  
  def destroy
    @trait = Trait.find (params[:trait_id])
    @effect = @trait.trait_effects.find(params[:id])
    
    @effect.destroy
    
    respond_to do |format|
      flash[:notice]= 'Effect was successfully deleted.'
      format.html { redirect_to @trait }
      format.js # renders destroy.js.rjs
    end
  end
  
  def create
    @trait = Trait.find( params[:trait_id] )
    @effect = @trait.trait_effects.build( params[ :trait_effect ] )
    respond_to do |format|
      if @effect.save
        flash[:notice] = "Effect was successfully created."
        format.html { redirect_to @trait }
        format.js # renders create.js.rjs
      else
        format.html { redirect_to @trait }
        format.js do
          render :update do |page| 
            page.redirect_to @trait
          end
        end
      end
    end
  end
end
